package com.nikolaj.kuzan.test;

import org.neuroph.core.data.DataSet;
import org.neuroph.core.data.DataSetRow;
import org.neuroph.nnet.ElmanNetwork;
import org.neuroph.nnet.Hopfield;
import org.neuroph.nnet.JordanNetwork;

import java.util.Arrays;


public class ElmanSample {
    public static void main(String args[]) {

        DataSet trainingSet = new DataSet(9);
        trainingSet.addRow(new DataSetRow(new double[]{1, 0, 1, 1, 1, 1, 1, 0, 1})); // H letter
        trainingSet.addRow(new DataSetRow(new double[]{0, 1, 0, 0, 1, 0, 0, 1, 0})); // I letter


        JordanNetwork firstElman = new JordanNetwork(9,3,3,9);
        firstElman.randomizeWeights();

        firstElman.setInput(1, 0, 1, 1, 1, 1, 1, 0, 1);
        firstElman.calculate();
        double[] out = firstElman.getOutput();
        System.out.println(" Output: " + Arrays.toString(out));

        

        firstElman.learn(trainingSet);



        trainingSet = new DataSet(9);
        trainingSet.addRow(new DataSetRow(new double[]{1, 1, 1, 1, 1, 1, 1, 0, 1}));
        trainingSet.addRow(new DataSetRow(new double[]{0, 0, 0, 0, 1, 0, 0, 1, 0}));


        for (DataSetRow dataRow : trainingSet.getRows()) {

            firstElman.setInput(dataRow.getInput());
            firstElman.calculate();
            firstElman.calculate();

            double[] networkOutput = firstElman.getOutput();

            System.out.print("Input: " + Arrays.toString(dataRow.getInput()));
            System.out.println(" Output: " + Arrays.toString(networkOutput));
        }





    }
}
